package com.bea.ftd.routing.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bea.ftd.routing.event.RefreshRouteService;

@RestController
public class RefreshController {
	private static final Logger LOGGER = LoggerFactory.getLogger(RefreshController.class);
	
    @Autowired
    RefreshRouteService refreshRouteService;

    @RequestMapping("/refresh")
    public AjaxResponse refreshConfig(){
    	LOGGER.info("开始刷新配置");
    	try {
    		refreshRouteService.refreshRoute();
    		return new AjaxResponse("SUCCESS", "配置刷新成功");
		} catch (Exception e) {
			LOGGER.error("配置刷新失败：" + e.getMessage());
			return new AjaxResponse("FAIL", "配置刷新失败，请重新刷新或者联系运维人员");
		}
    }
        
    private class AjaxResponse {
    	private String status;
    	private String message;
    	
    	public AjaxResponse(String status, String message) {
    		super();
    		this.status = status;
    		this.message = message;
    	}

		public String getStatus() {
			return status;
		}

		public void setStatus(String status) {
			this.status = status;
		}

		public String getMessage() {
			return message;
		}

		public void setMessage(String message) {
			this.message = message;
		}
    	
    }

}
